package com.fau.wm.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * @desc 库存表实体类
 * @author kangyj
 * @datetime 2014年8月8日,下午5:58:30
 */
@Entity
@Table(name = "medical_in_stock")
public class MedicalInStock implements Serializable, JSONAware {

	private static final long serialVersionUID = -7260664367421984043L;
	
	private String id;
	
	private Integer quantity;			// 数量
	private MedicalMedicine medicine;	// 药品实体类
	private MedicalWarehouse warehouse;	// 仓库实体类
	private String hospitalId;			//医院标识id
	
	private String warehouseId;		// 仓库id
	private String medicineId;		// 药品id
	private String medicineName;    // 药品名称
	private String warehouseName;   // 仓库名称
	private String medicineType;   // 药品类别

	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Transient
	public String getMedicineId() {
		return medicineId;
	}

	public void setMedicineId(String medicineId) {
		this.medicineId = medicineId;
	}

	@Transient
	public String getWarehouseId() {
		return warehouseId;
	}

	public void setWarehouseId(String warehouseId) {
		this.warehouseId = warehouseId;
	}

	@Column(name = "quantity", length = 11)
	public Integer getQuantity() {
		return quantity;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "medicine_id")
	public MedicalMedicine getMedicine() {
		return medicine;
	}
	
	@Transient
	public String getMedicineName() {
		return medicineName;
	}

	public void setMedicineName(String medicineName) {
		this.medicineName = medicineName;
	}

	public void setMedicine(MedicalMedicine medicine) {
		this.medicine = medicine;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "warehouse_id")
	public MedicalWarehouse getWarehouse() {
		return warehouse;
	}

	public void setWarehouse(MedicalWarehouse warehouse) {
		this.warehouse = warehouse;
	}
	
	@Transient
	public String getWarehouseName() {
		return warehouseName;
	}

	public void setWarehouseName(String warehouseName) {
		this.warehouseName = warehouseName;
	}

	@Column(name="hospital_id",length = 32)
	public String getHospitalId() {
		return hospitalId;
	}

	public void setHospitalId(String hospitalId) {
		this.hospitalId = hospitalId;
	}

	@Transient
	public String getMedicineType() {
		return medicineType;
	}

	public void setMedicineType(String medicineType) {
		this.medicineType = medicineType;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("medicineId", medicine.getId());
		obj.put("medicineSerialNum", medicine.getSerialNum());
		obj.put("medicineName", medicine.getName());
		obj.put("medicineUnit", medicine.getUnitValue());
		obj.put("medicineTypeValue", medicine.getMedicineTypeValue());
		obj.put("warehouseId", warehouse.getId());
		obj.put("warehouseName", warehouse.getName());
		obj.put("quantity", quantity);
		
		return obj.toString();
	}

}
